/*
下载依赖包 npm i init   npm i express mongoose ejs
1.链接数据库
*/

//引入mongoose
const mongoose = require("mongoose")

//连接数据库
mongoose.connect("mongodb://127.0.0.1:27017/book-crud")  //connect (连接)

//向外暴露绑定监视函数
//让调用者传入连接成功和失败的回调
module.exports = (onSuccess, onError) => {
    //绑定连接成功的回调
    mongoose.connection.on("open",onSuccess)

    //绑定连接失败的回调
    mongoose.connection.on("error",onError)
}
